package org.siberia.client.action;

import java.util.ArrayList;
import java.util.List;

import org.siberia.client.bean.UserDTO;
import org.siberia.client.service.UserService;
import org.siberia.client.service.UserServiceAsync;

import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class FeedDataAction implements Action
{
	@Override
	public void run()
	{
		UserServiceAsync userService = GWT.create(UserService.class);
		
		List<UserDTO> users = new ArrayList<UserDTO>();
		UserDTO alexis = new UserDTO();
		alexis.username = "Alexis";
		UserDTO sophie = new UserDTO();
		sophie.username = "Sophie";
		users.add(alexis);
		users.add(sophie);
		
		for(int i = 0; i < users.size(); i++)
		{
			final UserDTO current = users.get(i);
			
			userService.createUser(current, new AsyncCallback<Void>()
			{
				@Override
				public void onFailure(Throwable caught)
				{
					MessageBox.info("error", "error when trying to create " + current.username, null);
				}

				@Override
				public void onSuccess(Void result)
				{
					MessageBox.info("info", "feed done", null);
				}
			});
		}
	}
}
